/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author VietLH
 */
public class OptionMessage {

    private JFrame parent;
    private JDialog dialogParent;

    public OptionMessage(JFrame parent) {
        this.parent = parent;
    }

    public OptionMessage(JDialog dialogParent) {
        this.dialogParent = dialogParent;
    }

    public OptionMessage(Object parentObject) {
        if (parentObject instanceof JFrame) {
            this.parent = (JFrame) parentObject;
        } else if (parentObject instanceof JDialog) {
            this.dialogParent = (JDialog) parentObject;
        }
    }

    public void showMessage(String message) {
        JOptionPane.showMessageDialog(parent, message, "Notice", JOptionPane.INFORMATION_MESSAGE);
    }

    public void showErrorMessage(String message) {
        JOptionPane.showMessageDialog(parent, message, "Error", JOptionPane.ERROR_MESSAGE);
    }

    public void confirmExit() {
        if (dialogParent != null) {
            int op = JOptionPane.showConfirmDialog(dialogParent, "Are you sure to exit?", "Exit", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (op == 0) {
                dialogParent.dispose();
            }
        }
        else if(parent!=null){
            int op = JOptionPane.showConfirmDialog(parent, "Are you sure to exit?", "Exit", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (op == 0) {
                parent.dispose();
            }
        }
    }

       public boolean confirmDelete(String text){
         if (parent != null) {
            int op = JOptionPane.showConfirmDialog(parent, "Are you sure to delete "+text+"?", "Delete", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (op == 0) {
                return true;
            }

        }
         return false;
    }

}
